package IO.xml.comprehension;

import java.io.IOException;

import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.AttributesImpl;

/**
 * Class XMLReader
 * @author mathieu
 */
public class ComprehensionReader implements XMLReader  
{
	private ContentHandler handler;
	private AttributesImpl atts = new AttributesImpl();
		
	@Override
	public void parse(InputSource arg0) throws IOException, SAXException 
	{
		if(handler == null)
		{
			throw new SAXException("Pas de ContentHandler");
		}
		
		ComprehensionSource source = (ComprehensionSource)arg0;
		handler = source.getXml().ecriture(handler, atts);
	}
	
	@Override
	public void setContentHandler(ContentHandler arg0) {this.handler = arg0;}
	
	@Override
	public ContentHandler getContentHandler() {return handler;}
	
	@Override
	public void parse(String arg0) throws IOException, SAXException
	{
		String m = "Le seul argument possible pour parse est un xml";
		throw new SAXException(m);
	}

	@Override
	public DTDHandler getDTDHandler() {return null;}

	@Override
	public EntityResolver getEntityResolver() {return null;}

	@Override
	public ErrorHandler getErrorHandler() {return null;}

	@Override
	public boolean getFeature(String arg0) throws SAXNotRecognizedException, SAXNotSupportedException {return false;}

	@Override
	public Object getProperty(String arg0) throws SAXNotRecognizedException, SAXNotSupportedException {return null;}

	@Override
	public void setDTDHandler(DTDHandler arg0) {}

	@Override
	public void setEntityResolver(EntityResolver arg0) {}

	@Override
	public void setErrorHandler(ErrorHandler arg0) {}

	@Override
	public void setFeature(String arg0, boolean arg1) throws SAXNotRecognizedException, SAXNotSupportedException {}

	@Override
	public void setProperty(String arg0, Object arg1) throws SAXNotRecognizedException, SAXNotSupportedException {}
}
